import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:nav_router/nav_router.dart';
import 'package:flutter_module/config/config.dart';
import 'package:flutter_module/config/const.dart';
import 'package:flutter_module/pages/root/root_page.dart';
import 'package:oktoast/oktoast.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:flutter_module/commom/commom.dart';

import 'FallbackCupertinoLocalisationsDelegate.dart';
import 'LocalizationsDelegate.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    print("project start1");
    if(Platform.isIOS){
      //ios相关代码
      //iOS 获取位置信息授权请求，iOS 特有
      //Connectivity().requestLocationServiceAuthorization();
    }else if(Platform.isAndroid){
      //android相关代码
    }
    print("requestPermission start1");
    requestPermission();
    print("requestPermission stop1");
    return OKToast(
      //2. wrap your app with OKToast
      textStyle: TextStyle(fontSize: 19.0, color: Colors.white),
      backgroundColor: Colors.grey,
      radius: 10.0,
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: title,
        navigatorKey: navGK,
        theme: ThemeData(
          indicatorColor: appBarColor,
          scaffoldBackgroundColor: bgColor,
          hintColor: Colors.grey.withOpacity(0.3),
          splashColor: Colors.transparent,
          canvasColor: Colors.transparent,
        ),
        localizationsDelegates: [
          // ... app-specific localization delegate[s] here
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          DemoLocalizationsDelegate.delegate,
          FallbackCupertinoLocalisationsDelegate.delegate,
        ],
        supportedLocales: [
            const Locale('en'), // English
            const Locale('zh'),
            // ... other locales the app supports
          ],
          // ...
        home: new RootPage(),
      ),
      animationCurve: Curves.easeIn,
      animationBuilder: Miui10AnimBuilder(),
      animationDuration: Duration(milliseconds: 200),
      duration: Duration(seconds: 3),
    );
  }
}

Future requestPermission() async {
  //请求权限
  Map<PermissionGroup, PermissionStatus> permissions =
  await PermissionHandler()
      .requestPermissions([PermissionGroup.location,PermissionGroup.camera,PermissionGroup.storage]);
  //校验权限
  if(permissions[PermissionGroup.camera] != PermissionStatus.granted){
    print("无照相权限");
  }
  if(permissions[PermissionGroup.location] != PermissionStatus.granted){
    print("无定位权限");
  }
}